home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / pcfig4th.zip / 4TH-FILE.ASM < prev    next >
Assembly Source File  |  1983-07-30  |  4KB  |  193 lines

  1. SUBTTL MS-DOS file interface words
  2. PAGE
  3.  
  4.  
  5. ;FORTH - MSDOS file interface
  6.  
  7. ;This is SYSTEM-DEPENDENT code and is normally INCLUDED by
  8. ;4TH-SYSD.ASM
  9.  
  10. REQUEST        EQU    33        ;MSDOS function request intr.
  11. FOPEN        EQU    15        ;open file function no.
  12. FCLOSE        EQU    16        ;close file function no.
  13. FREAD        EQU    20        ;sequential read
  14. FWRITE        EQU    21        ;    "      write
  15. FCREAT        EQU    22        ;create file
  16. SETDTA        EQU    26        ;set disk transfer address
  17. RANDRD        EQU    39        ;random block read
  18. RANDWRT        EQU    40        ;random block write
  19. FSIZE        EQU    35        ;determine file size
  20. PARSEFN        EQU    41        ;parse file name function
  21. SETVEC        EQU    37        ;set interrupt vector
  22. FATADDR        EQU    27        ;get alloc. table info.
  23.  
  24. ;=C+  (OPEN)    open FCB, f is TRUE if error        FCB -- f
  25.  
  26.     $CODE    86H,(OPEN,)
  27.         POP    DX        ;DX points to FCB
  28.         MOV    AH,FOPEN
  29.         INT    REQUEST
  30.         SUB    AH,AH
  31.         JMP    APUSH        ;Leave 0FFH if not found
  32.  
  33. ;=C+  (CLOSE)    close FCB, f is TRUE on error        FCB -- f
  34.  
  35.     $CODE    87H,(CLOSE,)
  36.         POP    DX        ;DX points to FCB
  37.         MOV    AH,FCLOSE
  38.         INT    REQUEST
  39.         SUB    AH,AH
  40.         JMP    APUSH        ;leave 0FFH if not found
  41.  
  42. ;=C+  (CREATE)    create file, f is TRUE on error        FCB -- f
  43.  
  44.     $CODE    88H,(CREATE,)
  45.         POP    DX        ;DX points to unopened FCB
  46.         MOV    AH,FCREAT
  47.         INT    REQUEST
  48.         SUB    AH,AH
  49.         JMP    APUSH        ;leave 0FFH if no room
  50.  
  51. ;=C+  (READ)    read next record from file to addr    FCB addr -- f
  52.  
  53.     $CODE    86H,(READ,)
  54.         POP    DX        ;DX has DTA
  55.         MOV    AH,SETDTA
  56.         INT    REQUEST
  57.         POP    DX        ;DX points to open FCB
  58.         MOV    AH,FREAD
  59.         INT    REQUEST
  60.         SUB    AH,AH
  61.         JMP    APUSH        ;AL has condition code
  62.  
  63. ;=C+  (WRITE)    write next record to file from addr    FCB addr -- f
  64.  
  65.     $CODE    87H,(WRITE,)
  66.         POP    DX
  67.         MOV    AH,SETDTA
  68.         INT    REQUEST
  69.         POP    DX        ;DX points to open FCB
  70.         MOV    AH,FWRITE
  71.         INT    REQUEST
  72.         SUB    AH,AH
  73.         JMP    APUSH        ;AL returns condition
  74.  
  75. ;=C+  (FBLKRD)    read n blocks from file            FCB n -- f
  76.  
  77.     $CODE    88H,(FBLKRD,)
  78.         MOV    DX,2[DTA]    ;Set DTA
  79.         MOV    AH,SETDTA
  80.         INT    REQUEST
  81.         POP    CX        ;read this many records
  82.         POP    DX        ;DX has FCB address
  83.         MOV    AX,2[REC]    ;Read this record
  84.         MOV    BX,DX
  85.         MOV    33[BX],AX    ;Set random record field
  86.         MOV    AH,RANDRD
  87.         INT    REQUEST
  88.         SUB    AH,AH        ;Return condition code
  89.         JMP    APUSH
  90.  
  91. ;=C+  (FBLKWRT)    write n blocks to file            FCB n -- f
  92.  
  93.     $CODE    89H,(FBLKWRT,)
  94.         MOV    DX,2[DTA]    ;Set DTA as for READ above
  95.         MOV    AH,SETDTA
  96.         INT    REQUEST
  97.         POP    CX        ;read this many records
  98.         POP    DX        ;FCB address
  99.         MOV    AX,2[REC]
  100.         MOV    BX,DX
  101.         MOV    33[BX],AX
  102.         MOV    AH,RANDWRT
  103.         INT    REQUEST
  104.         SUB    AH,AH
  105.         JMP    APUSH
  106.  
  107. ;=C+  B/SEC    get bytes/sector            -- n
  108.  
  109.     $CODE    86H,B/SEC,?
  110.         PUSH    DS        ;This fn. kills DS !
  111.         MOV    AH,FATADDR
  112.         INT    REQUEST
  113.         POP    DS        ;Don't lose it !
  114.         PUSH    CX        ;sector size
  115.         JMP    NEXT
  116.  
  117. ;=C+  (FNAME)    parse filename at addr using mode n    FCB addr1 n -- addr2 f
  118.  
  119.     $CODE    87H,(FNAME,)
  120.         POP    AX        ;mode in AL
  121.         POP    BX        ;pointer to string
  122.         POP    DI        ;pointer to FCB to fill in
  123.         PUSH    SI        ;save FORTH IP
  124.         MOV    SI,BX
  125.         MOV    AH,PARSEFN
  126.         INT    REQUEST
  127.         MOV    DX,SI        ;return pointer to next char
  128.         POP    SI
  129.         SUB    AH,AH
  130.         JMP    DPUSH        ;...and flag for "*|?"
  131.  
  132. ;=C+  DISK    set default drive to n, n2 is #drives    n -- n2
  133.  
  134.         $CODE    84H,DIS,K
  135.         POP    DX
  136.         SUB    DH,DH
  137.         MOV    AH,14        ;select disk function
  138.         INT    REQUEST
  139.         SUB    AH,AH
  140.         JMP    APUSH        ;return no. drives
  141.  
  142. ;=C+  ?FIRST    search for first matching file        FCB addr -- f
  143.  
  144.         $CODE    86H,!!!?FIRS,T
  145.         POP    DX        ;destination addr.
  146.         MOV    AH,SETDTA
  147.         INT    REQUEST
  148.         POP    DX        ;search FCB addr.
  149.         MOV    AH,17        ;search for first entry
  150.         INT    REQUEST
  151.         SUB    AH,AH
  152.         JMP    APUSH
  153.  
  154. ;=C+  ?NEXT    search for next matching file        addr FCB -- f
  155.  
  156.         $CODE    85H,!!!?NEX,T
  157.         POP    DX        ;dest. addr.
  158.         MOV    AH,SETDTA
  159.         INT    REQUEST
  160.         POP    DX        ;search FCB addr.
  161.         MOV    AH,18        ;search for next entry
  162.         INT    REQUEST
  163.         SUB    AH,AH
  164.         JMP    APUSH
  165.  
  166. ;=C+  FDEL    delete file                FCB -- f
  167.  
  168.         $CODE    84H,FDE,L
  169.         POP    DX        ;unopened FCB
  170.         MOV    AH,19        ;delete file function
  171.         INT    REQUEST
  172.         SUB    AH,AH
  173.         JMP    APUSH
  174.  
  175. ;=C+  FREN    rename file                addr -- f
  176.  
  177.         $CODE    84H,FRE,N
  178.         POP    DX        ;special FCB
  179.         MOV    AH,23        ;rename file
  180.         INT    REQUEST
  181.         SUB    AH,AH
  182.         JMP    APUSH
  183.  
  184. ;=C+  DISK@    return default disk number        -- n
  185.  
  186.         $CODE    85H,DISK,@
  187.         MOV    AH,25        ;return default disk
  188.         INT    REQUEST
  189.         SUB    AH,AH
  190.         JMP    APUSH
  191.  
  192.     $REPORT    <MS-DOS file interface included>
  193.